<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <form>
            <input type="text" v-model="user.username">
            <input type="text" v-model="user.age">
            <button type="button" @click="doSubmit()">post提交</button>
        </form>
    </div>

    <script src="vue.min.js"></script>
    <script src="axios.min.js"></script>
    <script>
        new Vue({
            el: '#app',

            data:{
                user: {}
            },
            methods: {

                doSubmit() {
                    // 创建axios实例
                    const request = axios.create({
                        baseURL: 'http://localhost:8888/api',
                        timeout: 5000 
                    })

                    var user = {
                        username: 'helen',
                        age: 100
                    }

                    request({
                        url: '/demo05-axios-data-post',
                        method: 'post',
                        data: this.user //请求体中json字符串的传输方式
                    })
                }
            }
        })
    </script>
</body>
</html>